<template>
  <div>
    <el-form :model="queryParam" :inline=true style="display: flex">
      <el-form-item label="身份证号">
        <el-input v-model="queryParam.idCard" style="width:160px"/>
      </el-form-item>
      <el-form-item label="手机号">
        <el-input v-model="queryParam.phoneNo" style="width:160px"/>
      </el-form-item>
      <el-form-item label="客户名">
        <el-input v-model="queryParam.name" style="width:160px"/>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="queryPage">搜索</el-button>
      </el-form-item>
      <el-form-item>
        <el-button type="danger" @click="trigerPullOverdueData">拉取逾期</el-button>
      </el-form-item>
    </el-form>
    <el-table :data="tableData" stripe style="width: 100%">
      <el-table-column prop="productCode" label="产品" width="100"></el-table-column>
      <el-table-column prop="id" label="序号" width="60"></el-table-column>
      <el-table-column prop="name" label="客户名" width="80"></el-table-column>
      <el-table-column prop="phoneNo" label="手机号" width="110"></el-table-column>
      <el-table-column prop="idCard" label="身份证号" width="170"></el-table-column>
      <el-table-column prop="term" label="第几期" width="70"></el-table-column>
      <el-table-column prop="overdueDay" label="逾期天数" width="80"></el-table-column>
      <el-table-column prop="repayTotal" label="本期金额" width="80"></el-table-column>
      <el-table-column prop="remainingAmount" label="剩余金额" width="80"></el-table-column>
      <el-table-column
        label="操作"
        width="70">
        <template slot-scope="scope">
          <el-button @click="callPhone(scope.row)" type="text">打电话</el-button>
        </template>
      </el-table-column>
      <el-table-column prop="contactNum" label="联系次数" width="80"></el-table-column>
      <el-table-column prop="operatorId" label="催收员id" width="80"></el-table-column>
      <el-table-column prop="repayTime" label="还款时间" width="160">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.repayTime) }}</span>
        </template>
      </el-table-column>
      <el-table-column prop="createTime" label="创建时间" width="160">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.createTime) }}</span>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="pageTotal>0"
      :total="pageTotal"
      :page.sync="queryParam.pageNum"
      :limit.sync="queryParam.pageSize"
      @pagination="queryPage"
    />
  </div>
</template>

<script>
import {code2Name, parseTime, value2Name} from '@/utils'
import store from "../../../store";

export default {
  data() {
    return {
      // 查询参数
      pageTotal: 0,
      queryParam: {
        idCard: '',
        name: '',
        phoneNo: '',
        pageNum: 1,
        pageSize: 10
      },
      repayStatusEnums: store.listDictionary('repayStatus'),
      tableData: []
    }
  },
  mounted() {
    this.pageList()
  },
  methods: {
    parseTime,
    value2Name,
    code2Name,
    queryPage() {
      var _this = this
      _this.pageList()
    },
    pageList() {
      var _this = this
      this.$api.overduePageList(_this.queryParam).then(res => {
        if (res.code === '00000') {
          _this.tableData = res.data.pageList
          _this.pageTotal = res.data.pageTotal
        } else {
          _this.$message(res.msg)
        }
      }).catch(e => {
        console.log('接口访问异常!')
      })
    },
    trigerPullOverdueData() {
      let _this = this
      this.$api.pullOverdueData().then(res => {
        if (res.code === '00000') {
          _this.$message("触发成功")
        } else {
          _this.$message(res.msg)
        }
      }).catch(e => {
        console.log('接口访问异常!')
      })
    },
    callPhone(row) {
      let _this = this
      let param = {
        overdueInfoId: row.id,
        remark: ''
      }
      this.$api.overdueCallPhone(param).then(res => {
        if (res.code === '00000') {
          row.contactNum += 1
          _this.$message("电话呼打完毕")
        } else {
          _this.$message(res.msg)
        }
      }).catch(e => {
        console.log('接口访问异常!')
      })
    }
  }
}
</script>
